package ru.magicreader.server;

import java.io.IOException;

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;

public class PersistenceFacade {
	private static PersistenceFacade instance;
	
	private PersistenceManagerFactory pmf;
	private PersistenceManager persistenceManager;
	
	private PersistenceFacade() throws IOException {
		pmf = JDOHelper.getPersistenceManagerFactory("transactions-optional");
	}
	
	public static PersistenceFacade getInstance() {
		try {
			if(instance == null) 
				instance = new PersistenceFacade(); 
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		
		return instance; 
	}
	
	public PersistenceManager getPersistenceManager() {
		if(persistenceManager == null)
			persistenceManager = pmf.getPersistenceManager(); 
		
		return persistenceManager; 
	}
}
